/**
 * 获取学生信息明细
 * 
 * /admin/student/getDetail
 */

const User_info = require('../../../models/usersInfo')
const utils = require('../../../utils/index')
const $ = require('../../../utils/common')

const get_student_datail = async function (req, res) {
    try {
        // 根据user_id查询学生信息
        const sql_res = await User_info.findOne({
            where: {
                id: req.query.id
            },
            attributes: ['id', 'user_name', 'user_fullname', 
            'user_class', 'user_major', 'user_address',
            'user_id_card', 'user_phone', 'user_phone', 
            'user_short_number', 'user_email', 'user_qq',
            'user_wechat', 'user_remark', 'user_role', 'user_password',
            'user_sex', 'user_shengyuan'],
        })

        if (sql_res == null) {
            $.sendMessage(res, 1015, '无效id')
            return
        } 

        if (sql_res.dataValues.user_role != 'student') {
            $.sendMessage(res, 1015, '水平越权')
            return
        }

        res.json({
            code: 200,
            message: 'success',
            data: sql_res
        })

        // 日志
        utils.create_a_log(req, '学生详情', '浏览')
        return
    }
    catch(error) {
        $.sendMessage(res, 1015, 'error' + error)
        return
    }
    
}
    
module.exports = get_student_datail